package seqlist.leetcode;

public class Num92 {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode dummyHead = new ListNode();
        dummyHead.next=head;
        ListNode prev=dummyHead;
        ListNode cur=prev.next;
        //先让prev和cur走right-1步走到只当位置；
        for (int i = 0; i < left-1; i++) {
            prev=prev.next;
            cur=cur.next;
        }
        for (int i = 0; i < right-left; i++) {
            ListNode next=cur.next;
            //删除
            cur.next=next.next;
            //头插
            next.next=prev.next;
            prev.next=next;
        }
   return dummyHead.next;
    }
}
